home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / basic / key_fake.zip / KEY-FAKE.DOC < prev   
Text File  |  1987-05-14  |  17KB  |  382 lines

  1.        <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  2.  
  3.      KEY-FAKE.COM       Queues up keystrokes for use by a program.
  4.      ------------
  5.  
  6.      Command Syntax: key-fake <key codes>
  7.  
  8.      Notes:
  9.  
  10.     If you get tired of answering the same questions every time you
  11.     fire up your favorite software package, then key-fake may be for
  12.     you.  It will automatically supply the anwsers that you would
  13.     otherise type in at the keyboard.
  14.  
  15.      Key-fake is used is a batch program file; it immediately preceeds
  16.      the call to your program.  For example, if you get tired of answering
  17.      the question "Load Message File Y/N? " every time you run Turbo
  18.      Pascal, you could create a batch file, TP.BAT, that contains:
  19.  
  20.            key-fake "y"
  21.            turbo
  22.  
  23.      When you enter the command, TP, Turbo will fire up and the message
  24.      question will be automatically answered with a "y".
  25.  
  26.      Key-fake can accept a string of up to 127 characters which consists
  27.      of quoted text strings (as "y" above), ASCII codes (in decimal), and
  28.      extended ASCII codes (@ followed by a decimal code).
  29.  
  30.      For Example:
  31.  
  32.            key-fake "Hello" 13
  33.  
  34.      sends the string, Hello, followed by a carriage return (ASCII 13).
  35.  
  36.            key-fake @80 @80 @68
  37.  
  38.      sends 2 down arrow keystrokes followed by F10 function key.
  39.  
  40.      Back to the Turbo Pascal example, if you wanted to designate a main
  41.      file when you started, the TP.BAT would be:
  42.  
  43.            key-fake "ym%1" 13
  44.            Turbo
  45.  
  46.      Then if you enter the command:
  47.  
  48.            tb myfile.pas
  49.  
  50.      key-fake will supply the string, ymmyfile.pas<CR>, to Turbo; that's
  51.      the same sequence of keys you would have pressed manually.
  52.  
  53.      Special Case:  Some programs (such as Lotus 123) clear the keyboard
  54.      buffer when they start up.  To prevent this, key-fake has a special
  55.      code, 0.  To supply a return to 123, for example:
  56.  
  57.            key-fake 0 13
  58.            123
  59.  
  60.      When Lotus starts up, it checks to see if there is anything in the
  61.      keyboard buffer; key-fake says "no".  The next time it checks,
  62.      key-fake say "yes" and sends <CR> (ASCII 13).
  63.  
  64.      For more details, see
  65.  
  66.                    "KEY-FAKEing Keystrokes"
  67.                    Charles Petzold
  68.                    PC-Magazine, Vol. 4, NO. 26, December 24, 1986
  69.                    Programming Utilities, pp 215-223
  70.  
  71.        <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  72.  
  73.                               KEY-FAKE.DOC
  74.        (PC Magazine Vol 4 No 26 December 24, 1985 by C. Petzold)
  75.  
  76.      "Press any key to begin" is a tolerable but minor nuisance.  But
  77. can you live with programs that don't maintain configuration files and
  78. required you to enter your printer port number before you start?  Or
  79. all those that should have been designed to accept commands but which
  80. walk you through a series of questions and answers instead?  Do you
  81. find yourself entering the same few start-up commands every time you
  82. use them?
  83.  
  84.      Usually there's not too much you can do about these annoying
  85. program preliminaries.  YOu may have created batch files to change
  86. subdirectories and save much repetitive typing, but normal batch files
  87. don't help once your program begins to execute.
  88.  
  89.      KEY-FAKE is a utility designed to extend the usefulness of your
  90. batch files by letting you supply all the necessary initial keystrokes
  91. to programs automatically.  In addition to handling program
  92. preliminaries, KEY-FAKE can even be made to run a whole program
  93. without any keyboard intervention on your part.  Hard disk systems
  94. users often assemble a collection of short batch files (often with
  95. one-letter names) that help to navigate through the invariable maze of
  96. subdirectories and programs.  Yet once a program begins executing, it's
  97. on its own, and batch file processing doesn't take over again until you
  98. exit the program.
  99.  
  100.      KEY-FAKE extends the power of batch files by filling this gap.
  101. With KEY-FAKE you can put program commands in your batch files as a
  102. series of keystrokes.  When the batch file loads the program, these
  103. keystrokes are interpreted just as if you had typed them yourself.
  104.  
  105.      From one perspective, it would seem that this facility is provided
  106. by DOS 2.0 and later versions.  It's called redirection of standard
  107. input, and it permits you to substitute a file for the normal keyboard
  108. input.  Unfortunately, while redirection of standard input is useful in
  109. certain applications, it is not designed for and cannot be used to take
  110. care of your program preliminaries.
  111.  
  112.      For one thing, redirection only works with programs that use DOS
  113. function calls to get keyboard information.  Most large programs use
  114. the BIOS Interrupt 16h for keyboard input instead.  Another problem is
  115. that redirection of standard input is al all-or-nothing proposition.
  116. It doesn't switch back to the real keyboard when the redirected file
  117. ends.  Thus, if standard input is redirected from a file that is
  118. exhausted while the program is still running, the program will hang.
  119. The only keystroke command to which the machine will then respond is
  120. the drastic reboot.
  121.  
  122.      Unlike redirection of standard input, KEY-FAKE works with programs
  123. that use the BIOS Interrupt 16h for keyboard input.  More importantly,
  124. once KEY-FAKE runs out of keystrokes, it relinquishes control and lets
  125. you continue with the typing.
  126.  
  127.  
  128.  
  129.      The best way to understand how to use KEY-FAKE and what is does is
  130. by looking at a few simple examples.  Suppose that every time you enter
  131. BASICA you execute a COLOR command to create a blue border and
  132. background with yellow letters.  With KEY-FAKE, you could create a
  133. two-line batch file (perhaps called B.BAT) to load BASICA:
  134.  
  135.           KEY-FAKE "COLOR 14,1,1" 13 "CLS" 13
  136.           BASICA
  137.  
  138.      After BASICA loads, it begins to check for commands coming from
  139. the keyboard.  The first keystrokes it reads, in this case, are those
  140. that come from the KEY-FAKE parameter.  Rule number one, then, is that
  141. KEY-FAKE must be executed before the program that will use the
  142. keystrokes.
  143.  
  144.      Anything placed in quotation marks in the KEY-FAKE parameter is
  145. interpreted as normal text, just as if you typed it in at the keyboard.
  146. Simple decimal numbers (like the 13) are ASCII codes for non-printable
  147. characters or control codes.  A 13 is the Enter key, for example.
  148. Similarly, a 27 is the Escape key, a 9 the Tab key, and an 8 is the
  149. Backspace key.
  150.  
  151.      You may use single quotes or double quotes to delimit a test
  152. string.  This is handy if you have to simulate a typed quote sign.
  153. If your text string must include a double quote sign, for instance,
  154. use single quotes as delimiters.  (This is a neat trick used by the
  155. IBM and Microsoft Macro Assemblers to solve the perennial quote-
  156. within-quote problem.)
  157.  
  158.      You may also include the "extended ASCII" keys (decimal codes 128
  159. through 255) as part of the KEY-FAKE parameter.  These include the
  160. function keys, cursor movement keys, Alt-letter keys, Alt-number keys,
  161. Ins, and Del.  These keys are specified in KEY-FAKE by the "at" sign
  162. (@) followed immediately by the extended ASCII code.  For instance, if
  163. you usually use the F3 key to load a program when you enter the BASICA
  164. interpreter, you could add that key to the end of the KEY-FAKE command:
  165.  
  166.           KEY-FAKE "COLOR 14,1,1" 13 "CLS" 13 @61
  167.  
  168.      Suppose you have a terrific spelling checker called SpelRite.  The
  169. only problem is that it doesn't accept command line parameters.  Every
  170. time you run SpelRite, it asks you for the name of the file you want to
  171. check and the subdirectory where the dictionary is located.  You can
  172. fix this SpelRite problem with a two-line batch file called SR.BAT:
  173.  
  174.           KEY-FAKE "%1" 13 "\SPELRITE" 13
  175.           SPELRITE
  176.  
  177. When you enter SR followed by a filename, the name will be substituted
  178. for %1 when the batch file executes.  KEY-FAKE then answers the two
  179. questions for you.
  180.  
  181.  
  182.  
  183.  
  184.      Suppose that WordStar on the office PC-XT is used by beginners and
  185. experts.  The beginners like a help level of 3, but the experts prefer
  186. a help level of 1.  Two batch files using KEY-FAKE solve the problem.
  187. The first one (called WSB.BAT), for the beginners, just loads WordStar:
  188.  
  189.           CD\WORDSTAR
  190.           WS
  191.  
  192. The second batch file, for the experts (WSE.BAT), is similar except
  193. that it supplies the WordStar keystrokes to change the help level from
  194. the main menu:
  195.  
  196.           CD\WORDSTAR
  197.           KEY-FAKE "H1"
  198.           WS
  199.  
  200.      Suppose you want to skip the opening "Include error messages?
  201. (Y/N)" prompt in Turbo Pascal.  Set up a batch file with KEY-FAKE
  202. called T.BAT:
  203.  
  204.           CD\TURBOPAS
  205.           KEY-FAKE "Y"
  206.           TURBO
  207.  
  208. No patch, no DEBUG, no hex addresses, no problems with different Turbo
  209. Pascal versions.  Just a simple Y typed by KEY-FAKE instead.
  210.  
  211.      How would you like to print several WordStar files using one batch
  212. command.  Call this file WSP.BAT:
  213.  
  214.           CD\WORDSTAR
  215.           :CHECK
  216.           IF /%1==/ GOTO END
  217.           KEY-FAKE "P%1" 27 "X"
  218.           WS
  219.           SHIFT
  220.           GOTO CHECK
  221.           :END
  222.  
  223. You execute it by typing:  WSP file1 file2 file3 .....
  224.  
  225.      WSP.BAT uses the IF statement to check whether a program is
  226. present.  If so, the filename parameter is substituted for %1 in the
  227. KEY-FAKE command.  When WordStar begins executing, the first keystrokes
  228. it gets are P (for Print), the filename, as Esc (decimal 27), and X
  229. (for Exit).  WordStar won't exit until it has finished printing.  When
  230. it exits back to the batch file, WSP.BAT does a SHIFT command, making
  231. %1 the next file in the list, and goes through the routine again.
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.      Some programs, like Lotus's 1-2-3, clear out the keyboard buffer
  240. when they load.  This would ordinarily be a problem with KEY-FAKE, but
  241. KEY-FAKE has it licked.  When the digit 0 appears in a KEY-FAKE
  242. parameter, it takes on special meaning.  If a program checks to see
  243. if any keys are waiting, KEY-FAKE will say "No."  The program thinks
  244. that no keys are available and the buffer is clear.  When the program
  245. checks again, KEY-FAKE says "Yes" and delivers the next keystroke.
  246.  
  247.      Since virtually every time you enter 1-2-3 you do a File Retrieve
  248. command, a batch file (L.BAT) will load Lotus in a hurry:
  249.  
  250.           CD\LOTUS
  251.           KEY-FAKE 0 13 0 13 0 13 0 13 0 13 "/FR"
  252.           LOTUS
  253.  
  254. Make sure you have the system disk in drive A: before you run this one.
  255. The string of 0's and 13's was developed empirically, but it works
  256. well, skipping past the Lotus Access System Menu right into 1-2-3,
  257. ready to select a file.  Use KEY-FAKE and you'll have to be really
  258. quick if you want to read the copyright notice one more time.
  259.  
  260.      KEY-FAKE also helps out with some odd-ball batch file problems
  261. that may be difficult to handle with other methods.  For instance,
  262. suppose you have a batch file that changes the subdirectory, but at
  263. the end of the batch file you want to return to the directory from
  264. which it was executed.  The top of the batch file could save the
  265. subdirectory with the following commands:
  266.  
  267.           KEY-FAKE "CD" 26 13
  268.           COPY CON \RETDIR.BAT
  269.           CD >> \RETDIR.BAT
  270.  
  271. Here, KEY-FAKE supplies input to the subsequent COPY command.  The
  272. keystrokes are CD, a blank, a decimal 26 (Ctrl-Z or End-of-File), and
  273. a 13 (Enter).  With these keystrokes, COPY creates a file called
  274. RETDIR.BAT in the root directory.  This file contains only the
  275. characters CD and a blank.  Then, when the CD command is executed in
  276. the third line, its output (the current directory name) is redirected
  277. and appended to the RETDIR.BAT file.  Note the use of the double angle
  278. brackets for appending to a file rather than recreating it.
  279.  
  280.      Now you have a file called RETDIR.BAT in the root directory that
  281. contains a CD command to return to the current subdirectory.  The end
  282. of the batch file simply contains the following commands:
  283.  
  284.           CD \
  285.           RETDIR
  286.  
  287. This will then execute the batch file and return you to the
  288. subdirectory from which you started.
  289.  
  290.  
  291.  
  292.  
  293.  
  294.      You could even develop KEY-FAKE parameters that carry programs
  295. through an entire task.  For instance, you could import an ASCII table
  296. of numbers into 1-2-3, save it as a worksheet file, exit to the Lotus
  297. Access System Menu, convert the 1-2-3 file to a .DIF file, and then
  298. run a BASIC program that used the .DIF file, all by executing one
  299. batch file.
  300.  
  301.      Thus, if you have some applications involving several PC programs
  302. that you'd like to automate but that now require manual keystrokes,
  303. then KEY-FAKE may be just the answer.
  304.  
  305.      To recap the syntax, then, KEY-FAKE accepts anything within a pair
  306. of single or double quotes as normal keystrokes.  ASCII codes are
  307. specified by decimal numbers.  Decimal numbers preceded by the @ symbol
  308. are extended ASCII codes.  A zero (0) is a special code to signal to
  309. programs that the keyboard buffer is clear.  Anything else in the
  310. KEY-FAKE parameter is interpreted as "white space" delimiting valid
  311. parameters.  The KEY-FAKE program does no real error checking.
  312.  
  313.      Naturally, there are some limitations with KEY-FAKE.  The first
  314. is the length of the parameter.  PC-DOS limits command line parameters
  315. to 127 characters, including the blank that separates the parameter
  316. from the program name and the final carriage return.  This limits the
  317. number of keystrokes that KEY-FAKE can fake.  If the entire KEY-FAKE
  318. parameter is a string beginning with a quote and you leave out the
  319. final quote and you leave out the final quote (which is allowable),
  320. you'll be able to squeeze in 124 keystrokes.
  321.  
  322.      If a KEY-FAKE command is executed before a previous KEY-FAKE
  323. command has exhausted its stored keystrokes, the second execution will
  324. write over the remaining keystrokes from the first.  Watch out for
  325. this if you're nesting batch file executions.
  326.  
  327.      Some program get keyboard information directly from the hardware
  328. keyboard interrupt and will thus bypass KEY-FAKE.  Until XyQuest fixes
  329. their word processor (or comes out with a new version), KEY-FAKE will
  330. be entirely ignored by XyWrite II.
  331.  
  332.      Some programs continuously monitor the keyboard and retrieve
  333. keystrokes even if they are not able to use the keystrokes immediately.
  334. This means that you may find that KEY-FAKE will not work well when you
  335. are on-lien using a communications program.
  336.  
  337.      KEY-FAKE cannot simulate keystrokes not supported by the PC BIOS,
  338. such as Alt-Home.  Nor can it create different keystrokes for the two
  339. different Plus and Minus keys, which are used as separate commands by
  340. some program (most notably Framework).
  341.  
  342.      Although KEY-FAKE is a program that remains resident in memory,
  343. it may be executed an unlimited number of times during a single PC
  344. session.  KEY-FAKE only installs itself in memory the first time it
  345. is executed; subsequent executions take up no extra memory.
  346.  
  347.  
  348.  
  349.      The first time KEY-FAKE is run, it saves the vector address of
  350. Interrupt 16h and substitutes an address to its own routine.  It then
  351. decodes the parameter into keystrokes and saves them to its own
  352. internal buffer.  The decoding of the parameter accounts for about
  353. half of KEY-FAKE's code.
  354.  
  355.      Most large programs use Interrupt 16h to get keyboard information.
  356. (Smaller programs, like the DOS utilities, use the DOS Interrupt 21h to
  357. get keyboard information, but ultimately Interrupt 16h is invoked
  358. anyway.)  Normally, the PC's ROM BIOS answers an Interrupt 16h by just
  359. fishing keystrokes out of a small buffer that it maintains and handing
  360. them back to the calling program.  The keystrokes get in the buffer
  361. through the much more complex Interrupt 9h routine in the ROM BIOS.
  362. (Interrupt 9h is a hardware interrupt generated whenever a key is
  363. pressed.  The routine in the ROM BIOS gets the scan code of the key
  364. and must decode it into an ASCII or extended ASCII code before putting
  365. it in the keyboard buffer.)
  366.  
  367.      After KEY-FAKE is loaded, it intercepts Interrupt 16h calls and
  368. passes back keystrokes from its own internal buffer to the calling
  369. program.  When no more keystrokes are left, it simply lets the original
  370. Interrupt 16h operate normally.
  371.  
  372.      Subsequent executions of KEY-FAKE do not remain resident in
  373. memory.  KEY-FAKE searches through memory for its copyright notice.
  374. If it finds it, it knows that the program has been executed before.
  375. It then uses the keystroke buffer area allocated during the first
  376. execution and only has to decode the parameter.
  377.  
  378.      The best uses of KEY-FAKE will be those you cook up to automate
  379. your own applications.  Batch files are a big help in themselves, but
  380. KEY-FAKE really gives them a real boost in power.  And it's always
  381. nicer when your PC does your typing for you.
  382.